<template>
	<view class="container">
		<uni-nav-bar class="ch-nav" height="88rpx" backgroundColor="#ffffff" leftWidth="90rpx" rightWidth="90rpx" color="#333" :fixed="true" :padding="false" :border="true" @clickLeft="$goBack(1)" @clickRight="submit">
			<template slot="left">
				<image class="left" src="@/public/images/public/dhl_fhjt.png" mode="aspectFit"></image>
			</template>
			<text class="title">分析内容</text>
			<template slot="right">
				<text class="text-primary" :class="complete ? 'color-blue' : 'color-grey'">完成</text>
			</template>
		</uni-nav-bar>
		<ContentEditor :type="type" placeholder="请输入分析内容..." @change="contentChange"></ContentEditor>
	</view>
</template>

<script>
	import ContentEditor from '../components/ch-editor/ch-contenteditor.vue'
	export default {
		data() {
			return {
				type: 'freeContent',
				complete: false
			}
		},
		components: {
			ContentEditor
		},
		onLoad() {
			if(this.$Route.query.type){
				this.type = this.$Route.query.type
			}else{
				console.log('非法请求');
				uni.showToast({
					title: '请求数据错误，请返回重试',
					icon: 'none'
				})
				this.$goBack(1)
			}
		},
		onUnload() {
			uni.removeStorageSync('article_'+this.type);
		},
		methods: {
			submit() {
				console.log(this.html);
				if(this.complete){
					uni.$emit(this.type + '_Change', this.html)
					this.$goBack(1)
				}else{
					if(this.html) {
						let len = this.$CHS.checkTextLength(this.html)
						if(len < 100){
							uni.showToast({
								title: '内容长度不少于100字，当前字数：' + len,
								icon: 'none'
							})
						}
					}else{
						uni.showToast({
							title: '请输入内容',
							icon: 'none'
						})
					}
				}
			},
			contentChange(e) {
				console.log(e);
				this.html = e.html
				let len = this.$CHS.checkTextLength(e.html)
				if(len >= 100){
					this.complete = true
				}else{
					this.complete = false
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		.ch-nav{
			.text-primary{
				margin-right: 20rpx;
			}
		}
	}
</style>
